package com.qqb.controller;

import com.qqb.pojo.PaperType;
import com.qqb.service.PaperTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/paperType")
public class PaperTypeController {

    @Autowired
    private PaperTypeService paperTypeService;

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 从redis中查询所有学历列表，如果缓存中不存在，再去数据库中查找
     * @return
     */
    @GetMapping("/findAll")
    public List<PaperType> findAll() {
        List<PaperType> paperTypeList;
        paperTypeList = (List<PaperType>) redisTemplate.boundValueOps("PaperType").get();
        if (paperTypeList == null || paperTypeList.isEmpty()) {
            paperTypeList = paperTypeService.findAll();
        }
        return paperTypeList;
    }

}
